package cn.sczc.jh.client.websocket.encoder;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.alibaba.fastjson.JSON;

import cn.sczc.jh.client.websocket.vo.WebsocketMessageVo;

public class WebSocketMessageEncoder implements Encoder.Text<WebsocketMessageVo> {
	private static final Logger log = LogManager.getLogger(WebSocketMessageEncoder.class);
	
	@Override
	public void init(EndpointConfig endpointConfig) {
		
	}

	@Override
	public void destroy() {
		
	}

	@Override
	public String encode(WebsocketMessageVo object) throws EncodeException {
		try {
			return JSON.toJSONString(object);
		}catch(Exception e) {
			log.error("websocket发送消息转码失败",e);
		}
		return null;
	}

}
